import java.util.concurrent.CompletableFuture;

public class ProcessHandleTest {
    public static void main(String[] args) throws Exception{
        Runtime rt = Runtime.getRuntime();
        Process p = rt.exec("notepad.exe");
        ProcessHandle ph = p.toHandle();
        System.out.println(ph.isAlive());
        System.out.println(ph.pid());
        System.out.println(ph.parent());

        ProcessHandle.Info info = ph.info();
        System.out.println(info.command());
        System.out.println(info.arguments());
        System.out.println(info.startInstant());
        System.out.println(info.totalCpuDuration());

        CompletableFuture<ProcessHandle> cf = ph.onExit();
        cf.thenRunAsync(()->{
            System.out.println("exit!!!");
        });
        Thread.sleep(5000);
    }
}
